﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SqlServer.Types;

namespace OBUCare.Core.Common
{
    public static class MsSqlExtension
    {
        /// <summary>
        /// 将sql中的HierarchyId类型字段从byte数组转成SqlHierarchyId类型
        /// </summary>
        /// <param name="hid_byte"></param>
        /// <returns></returns>
        public static SqlHierarchyId ToSqlHierarchyId(this byte[] hid_byte)
        {
            var hierarchyID = Microsoft.SqlServer.Types.SqlHierarchyId.Null;
            if (hid_byte != null && hid_byte.Length > 0)
            {
                using (var stream = new System.IO.MemoryStream(hid_byte))
                {
                    using (var rdr = new System.IO.BinaryReader(stream))
                    {
                        hierarchyID.Read(rdr);
                    }
                }
            }

            return hierarchyID;
        }

    }
}
